idf_build_get_property(target IDF_TARGET)

set(srcs "stdin_out.c"
    "addr_from_stdin.c"
    "connect.c"
    "wifi_connect.c"
    "protocol_examples_utils.c")

if(CONFIG_EXAMPLE_PROVIDE_WIFI_CONSOLE_CMD)
    list(APPEND srcs "console_cmd.c")
endif()

if(CONFIG_EXAMPLE_CONNECT_ETHERNET)
    list(APPEND srcs "eth_connect.c")
endif()

idf_component_register(SRCS "${srcs}"
    INCLUDE_DIRS "include"
    PRIV_REQUIRES esp_netif driver esp_wifi vfs)

if(CONFIG_EXAMPLE_PROVIDE_WIFI_CONSOLE_CMD)
    idf_component_optional_requires(PRIVATE console)
endif()

if(CONFIG_EXAMPLE_CONNECT_ETHERNET)
    idf_component_optional_requires(PRIVATE esp_eth)
endif()

# After build, copy the archive file and header file to parent example directory's main component
if (PREBUILT_DIRECTORY)
    file(MAKE_DIRECTORY ${PREBUILT_DIRECTORY}/include/protocol_examples_common)
    file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${PREBUILT_DIRECTORY}/include/protocol_examples_common)
	add_custom_command(TARGET ${COMPONENT_LIB} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${COMPONENT_LIB}> ${PREBUILT_DIRECTORY}/lib COMMENT "Copying built archive file to prebuilt directory...")
endif()
